package com.hq.ims.data.service;


import com.hq.ims.data.dao.CompanyChangeHistoryMapper;
import com.hq.ims.data.entity.CompanyChangeHistory;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.mybatis.base.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @Author jiang bai ping
 * @Email 526666031@qq.com
 * @DateTime 2024-10-28 09:05:29
 * @Detail 公司变更记录服务实现类
 */
@Service
public class BaseCompanyChangeHistoryService extends BaseService<CompanyChangeHistoryMapper, CompanyChangeHistory> {

    public List<CompanyChangeHistory> getChangListByCompanyId(String companyId, Integer changType) {
        return this.lambdaQuery().eq(CompanyChangeHistory::getCompanyId, companyId)
                .eq(CompanyChangeHistory::getChangeType, changType)
                .orderByDesc(CompanyChangeHistory::getCreateDateTime)
                .list();
    }

    public CompanyChangeHistory getChangeInfoByCheckId(String checkId) {
        return this.lambdaQuery().eq(CompanyChangeHistory::getCompanyCheckId, checkId).orderByDesc(CompanyChangeHistory::getCreateDateTime).last(LocalConstant.LIMIT_1).one();
    }

    @Transactional(rollbackFor = Exception.class)
    public void delByCompanyId(String companyId) {
        this.lambdaUpdate().eq(CompanyChangeHistory::getCompanyId,companyId).remove();
    }
}
